@extends('admin.layout.common')
@section('content')
    <link rel="stylesheet" type="text/css" href="{{URL::asset('css/user/StaffManagement.css')}}">
    <link rel="stylesheet" type="text/css" href="{{URL::asset('css/app.css')}}">
    <div class="content">
        <h1 class="h1" style="width:180px;">业务员管理</h1>
        <p style="text-align: right;margin-right:20px;"><button type="submit" value="增加业务员" class="add_salesman" onclick="addSale()" >增加业务员</button></p>
        <table border="1" width="100%">
            <thead>
            <tr>
                <th>业务员ID</th>
                <th>姓名</th>
                <th>手机号</th>
                <th>邮箱</th>
                <th>权限</th>
                <th>入职时间</th>
                <th>操作</th>
            </tr>
            </thead>
            @foreach($list as $v)
            <tr id="datatable-responsive" class="id">
                <td>{{$v->id}}</td>
                <td>{{$v->name}}</td>
                <td>{{$v->phone}}</td>
                <td>{{$v->email}}</td>
                <td>{{$v->type}}</td>
                <td>{{$v->create_at}}</td>
                <td>
                    <input type="button" name="" value="编辑" onclick=edit({{$v->id}})>
                    @if($v->status==1)
                    <input type="button" name="" value="解绑" class="dimission_click unbind" onclick=unbind("{{$v->name}}")>
                    @endif
                    @if($v->status==2)
                    <input type="button" name="" value="离职" class="dimission_click dimission" onclick=exit({{$v->id}})>
                    @endif
                    @if($v->status==0)
                        <input type="button" name="" value="已离职" class="dimission_click dimission" style="border:none;background-color:#CF2121;color:#fff;">
                    @endif
                </td>
            </tr>
            @endforeach
        </table>
        {{ $list->links() }}
    </div>

    <script>
      //增加业务
      function addSale() {
        layer.open({
          type: 2,
          shadeClose: true, //点击遮罩关闭
          skin: 'layui-layer-rim', //加上边框
          area: ['700px', '700px'], //宽高
          content: "http://{{$_SERVER['HTTP_HOST']}}/admin/addSale"
          ,end: function () {
            location.reload();
          }
        });
      }
      //解绑弹窗
      function unbind(name){
        layer.open({
          type: 2,
          shadeClose: true, //点击遮罩关闭
          skin: 'layui-layer-rim', //加上边框
          area: ['580px', '450px'], //宽高
          content: 'http://{{$_SERVER['HTTP_HOST']}}/admin/unbind/'+name
          ,end: function () {
            location.reload();
          }
        });
      }

      //编辑
      function edit(id) {
        layer.open({
          type: 2,
          shadeClose: true, //点击遮罩关闭
          skin: 'layui-layer-rim', //加上边框
          area: ['800px', '650px'], //宽高
          content: "http://{{$_SERVER['HTTP_HOST']}}/admin/updateSale/"+id+'/0'
          ,end: function () {
            location.reload();
          }
        });
      }

      //离职弹窗
      function exit(id) {
        layer.confirm('确定办理离职！', {
           btn: ['确认','取消']
        }, function () {
          $.get("http://{{$_SERVER['HTTP_HOST']}}/admin/updateSale/"+id+'/1',function(){
            location.reload();
          });
        }, function () {
          layer.msg('已取消', {
            time: 2000, //2s后自动关闭
            // btn: ['明白了', '知道了']
          });
        });
      }
    </script>
@endsection


